<template>
	<view>
		<scroll-view scroll-y class="page">
			<!-- 头部 -->
			<cu-custom bgColor="bg-rgb" :isBack="true">
				<block slot="backText">返回</block>
				<block slot="content">点检</block>
			</cu-custom>
			<!-- 数据列表 -->
			<view class="list">
				<form>
					<view class="card animation-slide-bottom">
						<view class="bottom">
							<view class="box">
								<view class="lable">
									设备名称:
								</view>
								<view class="content">
									{{objMsg.deviceName}}
								</view>
							</view>
							<view class="box">
								<view class="lable">
									设备型号:
								</view>
								<view class="content">
									{{objMsg.deviceModel}}
								</view>
							</view>
							<view class="box">
								<view class="lable">
									点检类型:
								</view>
								<view class="content">
									<picker range-key="itemText" @change="kwChange" value="itemValue"
										:range="checkTypeList">
										<view class="picker">
											{{checkTypeList[index].itemText}}
										</view>
									</picker>
								</view>
							</view>
							<view v-if="['soldering_iron_check','tin_furnace_check'].indexOf(objMsg.query1) > -1">
								<view class="line"></view>
								<view class="box" v-for="item in ironList">
									<view class="lable">
										{{item.inspectionItems}}:
									</view>
									<view class="content">
										<input :placeholder="'请输入' + item.inspectionItems" style="text-align: right;"
											name="input" v-model="item.inspectionResults"></input>
									</view>
								</view>
							</view>
							<view v-for="(item,index) in checkList" :key="index" v-if="!loadding">
								<view class="line"></view>
								<view class="box">
									<view class="lable">
										点检项目:
									</view>
									<view class="content">
										{{item.inspectionItems}}
									</view>
								</view>
								<view class="box">
									<view class="lable">
										衡量标准:
									</view>
									<view class="content">
										{{item.measureStandard}}
									</view>
								</view>
								<view class="box">
									<view class="lable">
										点检结果:
									</view>
									<view class="content">
										<radio-group @change="radioChange($event,index)">
											<label class="radio" v-for="(filed,i) in resultList">
												<radio style="margin: 0 10rpx;" :value="filed.value"
													:checked="item.inspectionResults === filed.value" />{{filed.type}}
											</label>
										</radio-group>
									</view>
								</view>
							</view>
							<view class="line"></view>
							<view class="box">
								<view class="lable">
									点检人:
								</view>
								<view class="content">
									<input placeholder="请输入点检人" v-model="maintainer"></input>
								</view>
							</view>
							<view class="box">
								<view class="lable">
									稽查人:
								</view>
								<view class="content">
									<input placeholder="请输入稽查人" v-model="reviewer"></input>
								</view>
							</view>
						</view>
						<view class="line"></view>
						<view class="btns" v-if="!loadding">
							<button @click="onSubmit" class="cu-btn bg-rgb shadow lg">保存</button>
						</view>
					</view>
				</form>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		name: 'shelvesGoods',
		data() {
			return {
				loadding: true,
				myFormData: {
					goodsId: '',
					barcode: ''
				},
				objMsg: {}, // 上架单列表
				checkTypeList: [],
				resultList: [{
						type: '正常',
						value: '√',
					},
					{
						type: '异常',
						value: '×',
					},
					{
						type: '无此项',
						value: '—',
					}
				],
				index: 0,
				checkList: [],
				ironList: [],
				measure: {
					'0': '√',
					'1': '×',
					'2': '—',
				},
				maintainer: "",
				reviewer: "",
			}
		},
		onLoad(option) {
			this.objMsg = this.$Route.query.objMsg
			this.getCheckType()
		},
		methods: {
			getCheckType() {
				this.$http.get('sys/dict/queryDictItemByCheckCode', {
						params: {
							checkCode: this.objMsg.query1
						}
					})
					.then(res => {
						if (res.data.success) {
							this.checkTypeList = res.data.result
							this.getCheckList()
						} else {
							this.modal.show({
								type: 'error',
								content: res.data.message
							})
						}
					})
			},
			getCheckList() {
				this.loadding = true
				this.$http.get('chiefdata/facilityCheckTemp/queryByFacilityNameAndTempSort', {
					params: {
						facilityName: this.objMsg.query1,
						tempSort: this.checkTypeList[this.index].itemValue
					}
				}).then(res => {
					if (res.data.success) {
						let arr = []
						let iron = []
						this.checkList = []
						this.ironList = []
						res.data.result.forEach(item => {
							if (['soldering_iron_check', 'tin_furnace_check'].indexOf(this.objMsg.query1) >
								-1) {
								if (['烙铁编号', '锡炉编号', '点检时间', '设定温度', '实际温度'].indexOf(item.project) < 0) {
									arr.push({
										inspectionItems: item.project,
										measureStandard: item.standard,
										inspectionResults: '√',
									})
								} else {
									iron.push({
										inspectionItems: item.project,
										measureStandard: item.standard,
										inspectionResults: '',
									})
								}
							} else {
								arr.push({
									inspectionItems: item.project,
									measureStandard: item.standard,
									inspectionResults: '√',
								})
							}
						})
						this.checkList = arr
						this.ironList = iron
						this.loadding = false
						console.log(111, this.checkList)
						console.log(222, this.ironList)
					} else {
						this.modal.show({
							type: 'error',
							content: res.data.message
						})
					}
				})
			},
			radioChange(e, index) {
				this.checkList[index].inspectionResults = e.target.value
			},
			kwChange(e) {
				this.index = e.target.value
				this.getCheckList()
			},
			onSubmit() {
				console.log(111, this.checkList)
				let ironObj = null
				if (['soldering_iron_check', 'tin_furnace_check'].indexOf(this.objMsg.query1) > -1) {
					for(let i = 0;i < this.ironList.length;i++){
						if(!this.ironList[i].inspectionResults){
							ironObj = this.ironList[i]
							break;
						}
					}
				}
				if(ironObj){
					return this.modal.show({
						type: 'error',
						content: '请输入' + ironObj.inspectionItems
					})
				}
				if (!this.maintainer) {
					return this.modal.show({
						type: 'error',
						content: '请输入点检人!'
					})
				}
				if (!this.reviewer) {
					return this.modal.show({
						type: 'error',
						content: '请输入稽查人!'
					})
				}
				let list = this.checkList
				if (['soldering_iron_check', 'tin_furnace_check'].indexOf(this.objMsg.query1) > -1) {
					list = list.concat(this.ironList)
				}
				let obj = {
					equipmentSn: this.objMsg.deviceSn,
					maintainer: this.maintainer,
					projectVoList: list,
					tableNameCode: this.objMsg.query1,
					recordType: this.checkTypeList[this.index].itemValue,
					reviewer: this.reviewer,
				}
				this.save(obj)
			},
			save(obj) {
				this.$http.post('produce/mesMaintenanceRecordItem/addMaintenanceRecordItemForApp', obj).then(res => {
					if (res.data.success) {
						this.modal.show({
							type: 'success',
							content: res.data.message
						})
						uni.navigateBack({
							delta: 1
						})
					} else {
						this.modal.show({
							type: 'error',
							content: res.data.message
						})
					}
				})
			},
		},
	}
</script>

<style lang="less">
	page {
		background-color: #f1f1f1;

		.fixed {
			position: fixed;
			z-index: 1;
			width: 100%;
			background-color: white;
			height: 100rpx;
			border-bottom: 1rpx solid #eee;

			.last {
				border-bottom: 1rpx solid #eee;
				position: relative;

				.icon {
					width: 30rpx;
					height: 29rpx;
					position: absolute;
					top: 36rpx;
					left: 60rpx;
				}

				input {
					width: 686rpx;
					height: 68rpx;
					background: #FFFFFF;
					border: 1px solid #D5D8DF;
					border-radius: 34px;
					padding-left: 79rpx;
				}
			}
		}

		.list {
			/deep/ .uni-input-input {
				border: 1px solid #d5d5d5;
				padding-right: 10rpx;
				border-radius: 10rpx;
				box-sizing: border-box;
			}

			input {
				font-size: 14px;
				font-weight: normal;
			}

			.card {
				margin: 30rpx;
				box-shadow: 0px 0px 5rpx 2rpx rgba(0, 0, 0, 0.1);
				border-radius: 10rpx;
				background-color: white;

				.top {
					display: flex;
					align-items: center;
					justify-content: space-between;
					font-weight: bold;
					padding: 20rpx 30rpx;

					.left {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: 400;
						color: #485A75;
						line-height: 50rpx;
					}

					.right {
						font-size: 28rpx;
						font-family: PingFang SC;
						font-weight: bold;
						color: #191919;
						line-height: 50rpx;
					}
				}

				.line {
					width: 100%;
					height: 10rpx;
					background: #F3F5F9;
				}

				.bottom {
					padding: 20rpx 30rpx;

					.box {
						display: flex;
						justify-content: space-between;
						padding: 20rpx 0;
						align-items: center;

						.lable {
							color: #485A75;
							font-size: 28rpx;
						}

						.content {
							width: 70%;
							text-align: right;
							color: #191919;
							font-weight: bold;
							word-break: break-all;
						}

						.shrink {
							height: 40rpx;
							overflow: hidden;
							white-space: nowrap;
							/*不换行*/
							text-overflow: ellipsis;
							/*超出部分文字以...显示*/
							font-weight: 400;
						}

						.unfold {
							text-align: left;
							font-weight: 400;
						}
					}
				}

				.btns {
					display: flex;
					justify-content: flex-end;
					align-items: center;
					padding: 0 20rpx;
					font-size: 25rpx;
					padding: 20rpx 30rpx;

					view {
						width: 180rpx;
						height: 64rpx;
						line-height: 50rpx;
						color: white;
						border-radius: 30rpx;
						padding: 10rpx 20rpx;
						text-align: center;
					}

					.btn1 {
						background-image: radial-gradient(circle, #3F55E9, #5F71ED, #7D8CF0);
					}

					.btn2 {
						background-image: radial-gradient(circle, #716BA9, #362D85, #57509A);
					}

					.btn3 {
						background-image: radial-gradient(circle, #354D9E, #354D9E, #697BB7);
					}
				}
			}
		}
	}

	.none .none1 {
		font-size: 30rpx;
		text-align: center;
		margin: 20rpx 0;
		color: #999999;
	}

	.none2 {
		font-size: 30rpx;
		text-align: center;
		margin: 20rpx 0;
		color: #999999;
	}

	// picker {
	// 	font-size: 15px !important;
	// 	font-weight: bold !important;
	// }
</style>
